﻿using FinallyArchive__Application;
using FinallyArchive__Application.CURDBaseService;
using FinallyArchive__Comm;
using FinallyArchive__Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace FinallyArchive.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserService _service;
        public UserController(IUserService service)
        {
            _service = service;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userAccess"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult LoginUser(LoginUserDto login) 
        {
            return  Ok(_service.LoginUser(login));
        }

        [HttpGet]
        public ActionResult GetUserAll() 
        {
            return Ok(_service.GetUserAll());
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost]
        public Result AddUser(UserInputDto user) 
        {
            if (user != null) 
            {
                return new Result()
                {
                    Code = (ReusltEnum)200,
                    data = _service.AddUser(user),
                    Massage = "添加成功"
                };
            }
            return new Result()
            {
                Code = (ReusltEnum)500,
                data = _service.AddUser(user),
                Massage = "添加失败"
            };

        }


    }
}
